package com.cjy.userReport.service.base;

import javax.annotation.Resource;

import com.base.common.ConfigConstants;
import com.base.common.persistent.dao.TicketMapper;
import com.base.common.persistent.model.Ticket;

/**
 * 工单实现基类
 * 
 * @author Kevin Colin
 *
 */
public class TicketBaseServiceImpl implements TicketBaseService {

	@Resource
	private TicketMapper ticketMapper;

	/**
	 * 更新工单
	 * 
	 * @param ticket
	 * @return
	 */
	@Override
	public int updateTicketByTicketId(Ticket ticket) {
		/*
		 * try{ int result = ticketMapper.updateTicketById(ticket); if(result >
		 * 0) { return result; } else { return 0; } }catch(Exception exception)
		 * { return 0; }
		 */
		return 0;
	}

	/**
	 * 根据用户id和分类得到工单列表的总数
	 * 
	 * @param ticket
	 * @return
	 */
	@Override
	public int getTicketsPagessByUserIdAndCategories(Ticket ticket) {
		int totalTicketsCounts = ticketMapper
				.queryTotalByCategoriesAndUserId(ticket);
		int totalPages = (totalTicketsCounts % 15 == 0) ? (totalTicketsCounts / 15)
				: (totalTicketsCounts / 15 + 1);
		return totalPages;
	}

	@Override
	public int getStartNum(int page) {
		return (page - 1)
				* Integer.valueOf(ConfigConstants.INFOS_LIST_NUM.trim());

	}

	@Override
	public int getEndNum(int page) {
		return page * Integer.valueOf(ConfigConstants.INFOS_LIST_NUM.trim());
	}
}
